1
|
|
|
/* eslint-disable no-useless-escape */ |
2
|
|
|
function stripTrailingSlash(str: string): string { |
3
|
|
|
return str.endsWith("/") ? str.slice(0, -1) : str; |
4
|
|
|
} |
5
|
|
|
|
6
|
|
|
function isValidUrl(str: string): boolean { |
7
|
|
|
if (str.startsWith("http://") || str.startsWith("https://")) { |
8
|
|
|
try { |
9
|
|
|
const url = new URL(str); |
10
|
|
|
} catch (_) { |
11
|
|
|
return false; |
12
|
|
|
} |
13
|
|
|
return true; |
14
|
|
|
} |
15
|
|
|
return false; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
export function baseUrl(): string { |
19
|
|
|
const base = document.querySelector("meta[name='base-url']"); |
20
|
|
|
if (base !== null) { |
21
|
|
|
return stripTrailingSlash(base.getAttribute("content") ?? ""); |
22
|
|
|
} |
23
|
|
|
return ""; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
export function basePathname(): string { |
27
|
|
|
const base = baseUrl(); |
28
|
|
|
return isValidUrl(base) ? new URL(baseUrl()).pathname : ""; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
export function baseApiUrl(version = 1): string { |
32
|
|
|
return `${baseUrl()}/api/v${version}`; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* |
37
|
|
|
* @param imgFile The name of the img file, not inluding the /images/ path. |
38
|
|
|
*/ |
39
|
|
|
export function imageUrl(imgFile: string): string { |
40
|
|
|
return `${baseUrl()}/images/${imgFile}`; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Removes the base url or base pathname if the given url starts with them. |
45
|
|
|
* @param url |
46
|
|
|
*/ |
47
|
|
|
export function removeBaseUrl(url: string): string { |
48
|
|
|
const base = baseUrl(); |
49
|
|
|
if (url.startsWith(base)) { |
50
|
|
|
return url.substr(base.length); |
51
|
|
|
} |
52
|
|
|
const basePath = basePathname(); |
53
|
|
|
if (url.startsWith(basePath)) { |
54
|
|
|
return url.substr(basePath.length); |
55
|
|
|
} |
56
|
|
|
return url; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
export function jobShow(locale: string, jobId: number): string { |
60
|
|
|
return `${baseUrl()}/${locale}/jobs/${jobId}`; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
function applicationShow( |
64
|
|
|
locale: string, |
65
|
|
|
prefix: string, |
66
|
|
|
applicationId: number, |
67
|
|
|
jobId: number, |
68
|
|
|
): string { |
69
|
|
|
return `${baseUrl()}/${locale}/${prefix}/jobs/${jobId}/applications/${applicationId}`; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
function applicantShow( |
73
|
|
|
locale: string, |
74
|
|
|
prefix: string, |
75
|
|
|
applicantId: number, |
76
|
|
|
jobId: number, |
77
|
|
|
): string { |
78
|
|
|
return `${baseUrl()}/${locale}/${prefix}/jobs/${jobId}/applicants/${applicantId}`; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
export function managerApplicationShow( |
82
|
|
|
locale: string, |
83
|
|
|
applicationId: number, |
84
|
|
|
jobId: number, |
85
|
|
|
): string { |
86
|
|
|
return applicationShow(locale, "manager", applicationId, jobId); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
export function managerApplicantShow( |
90
|
|
|
locale: string, |
91
|
|
|
applicantId: number, |
92
|
|
|
jobId: number, |
93
|
|
|
): string { |
94
|
|
|
return applicantShow(locale, "manager", applicantId, jobId); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
export function managerEditProfile(locale: string): string { |
98
|
|
|
return `${baseUrl()}/${locale}/manager/profile`; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
export function managerJobIndex(locale: string): string { |
102
|
|
|
return `${baseUrl()}/${locale}/manager/jobs`; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
export function managerJobSummary(locale: string, jobId: number): string { |
106
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}`; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
export function managerJobPreview(locale: string, jobId: number): string { |
110
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/preview`; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
export function managerJobApplications(locale: string, jobId: number): string { |
114
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/applications`; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
export function managerScreeningPlan(locale: string, jobId: number): string { |
118
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/assessment-plan`; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
export function applicationReviewUpdate( |
122
|
|
|
locale: string, |
123
|
|
|
applicationId: number, |
124
|
|
|
): string { |
125
|
|
|
return `${baseApiUrl()}/applications/${applicationId}/review`; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
export function jobBuilderIntro(locale: string, jobId?: number): string { |
129
|
|
|
if (jobId) { |
130
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/intro`; |
131
|
|
|
} |
132
|
|
|
return `${baseUrl()}/${locale}/manager/job-builder/intro`; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
export function jobBuilderDetails(locale: string, jobId: number): string { |
136
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/details`; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
export function jobBuilderEnv(locale: string, jobId: number): string { |
140
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/environment`; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
export function jobBuilderImpact(locale: string, jobId: number): string { |
144
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/impact`; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
export function jobBuilderTasks(locale: string, jobId: number): string { |
148
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/tasks`; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
export function jobBuilderSkills(locale: string, jobId: number): string { |
152
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/skills`; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
export function jobBuilderReview(locale: string, jobId: number): string { |
156
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/review`; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
type FaqSection = "manager-who"; |
160
|
|
|
|
161
|
|
|
export function managerFaq(locale: string, faqSection?: FaqSection): string { |
162
|
|
|
const base = `${baseUrl()}/${locale}/manager/faq`; |
163
|
|
|
if (faqSection) { |
164
|
|
|
return `${base}#${faqSection}`; |
165
|
|
|
} |
166
|
|
|
return base; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
export function hrJobIndex(locale: string): string { |
170
|
|
|
return `${baseUrl()}/${locale}/hr/jobs`; |
171
|
|
|
} |
172
|
|
|
export function hrJobSummary(locale: string, jobId: number): string { |
173
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}`; |
174
|
|
|
} |
175
|
|
|
export function hrJobReview(locale: string, jobId: number): string { |
176
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/review`; |
177
|
|
|
} |
178
|
|
|
export function hrJobPreview(locale: string, jobId: number): string { |
179
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/preview`; |
180
|
|
|
} |
181
|
|
|
export function hrScreeningPlan(locale: string, jobId: number): string { |
182
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/assessment-plan`; |
183
|
|
|
} |
184
|
|
|
export function hrJobApplications(locale: string, jobId: number): string { |
185
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/applications`; |
186
|
|
|
} |
187
|
|
|
export const hrApplicationShow = ( |
188
|
|
|
locale: string, |
189
|
|
|
applicationId: number, |
190
|
|
|
jobId: number, |
191
|
|
|
): string => applicationShow(locale, "hr", applicationId, jobId); |
192
|
|
|
export const hrApplicantShow = ( |
193
|
|
|
locale: string, |
194
|
|
|
applicantId: number, |
195
|
|
|
jobId: number, |
196
|
|
|
): string => applicantShow(locale, "hr", applicantId, jobId); |
197
|
|
|
|
198
|
|
|
export function accountSettings(locale: string): string { |
199
|
|
|
return `${baseUrl()}/${locale}/settings`; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Converts a string to a url safe equivalent. |
204
|
|
|
* @param string Any input text. |
205
|
|
|
* @returns url safe string. |
206
|
|
|
*/ |
207
|
|
|
export function slugify(string: string): string { |
208
|
|
|
const a = |
209
|
|
|
"àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïíīįìłḿñńǹňôöòóœøōõőṕŕřßśšşșťțûüùúūǘůűųẃẍÿýžźż·/_,:;"; |
210
|
|
|
const b = |
211
|
|
|
"aaaaaaaaaacccddeeeeeeeegghiiiiiilmnnnnoooooooooprrsssssttuuuuuuuuuwxyyzzz------"; |
212
|
|
|
const p = new RegExp(a.split("").join("|"), "g"); |
213
|
|
|
|
214
|
|
|
return string |
215
|
|
|
.toString() |
216
|
|
|
.toLowerCase() |
217
|
|
|
.replace(/\s+/g, "-") // Replace spaces with - |
218
|
|
|
.replace(p, (c) => b.charAt(a.indexOf(c))) // Replace special characters |
219
|
|
|
.replace(/&/g, "-and-") // Replace & with 'and' |
220
|
|
|
.replace(/[^\w\-]+/g, "") // Remove all non-word characters |
221
|
|
|
.replace(/\-\-+/g, "-") // Replace multiple - with single - |
222
|
|
|
.replace(/^-+/, "") // Trim - from start of text |
223
|
|
|
.replace(/-+$/, ""); // Trim - from end of text |
224
|
|
|
} |
225
|
|
|
|